package com.smartfactory.sail.controller;


import com.ada.base.common.ApiResponse;
import com.ada.base.common.ControllerResponse;
import com.smartfactory.sail.config.BizzException;
import com.smartfactory.sail.config.OperRecord;
import com.smartfactory.sail.entity.ItemWorkingprocedureInfo;
import com.smartfactory.sail.service.IItemWorkingprocedureInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 产品生产流程详情 前端控制器
 * </p>
 *
 * @author 王巨壁
 * @since 2019-08-13
 */
@Api(tags = "产品生产详情")
@RestController
@RequestMapping("/item-workingprocedure-info")
public class ItemWorkingprocedureInfoController extends ControllerResponse {
    private IItemWorkingprocedureInfoService iItemWorkingprocedureInfoService;

    public ItemWorkingprocedureInfoController(IItemWorkingprocedureInfoService iItemWorkingprocedureInfoService) {
        this.iItemWorkingprocedureInfoService = iItemWorkingprocedureInfoService;
    }

    @OperRecord(content = "生产中,扫码提交生产信息",level = 0)
    @PostMapping
    @ApiOperation(value = "新增产品生产详情",notes = "新增产品生产详情")
    public ApiResponse<Integer> add(@RequestBody ItemWorkingprocedureInfo info) {
        try {
            return ok(iItemWorkingprocedureInfoService.scanInsert(info));
        } catch (BizzException e) {
            return fail(e.getMessage());
        }
    }

    @PutMapping("/repair/{id}/{count}")
    @ApiOperation(value = "修复工序产品",notes = "修复工序产品")
    public ApiResponse<Integer> repair(@PathVariable("id") long id, @PathVariable("count") int count) {
        iItemWorkingprocedureInfoService.repair(id, count);
        return ok();
    }
}
